//
//  QuickLoansViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/12/6.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class QuickLoansViewController: KMViewController {
    
    fileprivate var quickLoanView1 : QuickLoansStep1View! //上一步
    fileprivate var quickLoanView2 : QuickLoansStep2View! //下一步
    fileprivate var model = [String:String]() //申请信息

    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = quickLoan
        addSubView()
        
    }
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
        quickLoanView1 = QuickLoansStep1View.init(frame: self.view.bounds)
        quickLoanView1.delegate = self
        self.view.addSubview(quickLoanView1)
    }

}

extension QuickLoansViewController : QuickLoansStep1ViewDelegate,QuickLoansStep2ViewDelegate {
    
    //MAKR: 上一步
    func previousStepAction() {
        
        quickLoanView2.isHidden = true
    }
    
    //MARK: 下一步
    func nextStepAction() {
        
        if quickLoanView2 == nil {
            quickLoanView2 = QuickLoansStep2View.init(frame: self.view.bounds)
            quickLoanView2.delegate = self
            self.view.addSubview(quickLoanView2)
        }else{
            quickLoanView2.isHidden = false
        }
        
        //添加step1相关信息
        for (key,value) in quickLoanView1.model {
            model[key] = value
        }
    }
    
    //MARK: 立即申请
    func applyNowAction() {
        
        //添加step2相关信息
        for (key,value) in quickLoanView2.model {
            model[key] = value
        }
        
        KMTool.waiting()
        KMTool.requestMethod(.post, URLString: url_submitApplication, parameters: model, success: { (value, json) in
            
            KMTool.stop()
            
        }) {
            
            KMTool.stop()
        }
    }
}
